package com.chen.controller.service.impl;

import com.chen.controller.service.TestEntityService;
import com.chen.dao.TestEntityDao;
import com.chen.entity.TestEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Title:
 * @Description: to do
 * @Author: chenjiwei
 * @Date: 2020-10-28 23:12
 * @Version: 1.0.0
 */
@Service
public class TestEntitySreviceImpl extends BaseServiceImpl<TestEntity> implements TestEntityService {

    @Resource
    private TestEntityDao testEntityDao;

    @Override
    public List<TestEntity> findTest() {
        return testEntityDao.findTest();
    }

    @Override
    public JpaSpecificationExecutor<TestEntity> getBaseRepository() {
        return testEntityDao;
    }

    protected String filterForFindAll(){
        return "id-equal,text-equal";
    }

    public Page<TestEntity> findTestByPage(TestEntity t){
        return findAll(t, PageRequest.of(0, 5));
    }

    @Override
    public List<Map<String, Object>> findSql() {
        return this.nativeQueryForList("select * from user where id = ?", new ArrayList<Object>() {
            {
                this.add(23);
            }
        });
    }
}
